package com.amsp.oa.oademo.controller;

import com.amsp.oa.oademo.entity.EquipmentRepair;
import com.amsp.oa.oademo.service.EquipmentRepairService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;

@RestController
@RequestMapping("/api/equipment-repair")
@CrossOrigin
@Api(tags = "设备维修申请")
public class EquipmentRepairController {

    @Autowired
    private EquipmentRepairService equipmentRepairService;

    @PostMapping("/save")
    @ApiOperation("保存设备维修申请")
    public boolean save(@RequestBody EquipmentRepair equipmentRepair) {
        return equipmentRepairService.saveOrUpdate(equipmentRepair);
    }

    @GetMapping("/list")
    @ApiOperation("分页查询设备维修申请")
    public Page<EquipmentRepair> list(
            @RequestParam(defaultValue = "1") Integer current,
            @RequestParam(defaultValue = "10") Integer size,
            @RequestParam(required = false) String applicationUnit,
            @RequestParam(required = false) String equipmentNameSpec,
            @RequestParam(required = false) String equipmentCode,
            @RequestParam(required = false) String applicant,
            @RequestParam(required = false) LocalDate startDate,
            @RequestParam(required = false) LocalDate endDate) {
        return equipmentRepairService.getPage(current, size, applicationUnit, equipmentNameSpec,
                equipmentCode, applicant, startDate, endDate);
    }

    @GetMapping("/{id}")
    @ApiOperation("根据ID查询设备维修申请")
    public EquipmentRepair getById(@PathVariable Long id) {
        return equipmentRepairService.getById(id);
    }

    @DeleteMapping("/{id}")
    @ApiOperation("根据ID删除设备维修申请")
    public boolean delete(@PathVariable Long id) {
        return equipmentRepairService.removeById(id);
    }
}